package org.seoul.gtugs.client.ui;

import java.util.List;

import org.seoul.gtugs.shared.PhotoEntity;
import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.DockLayoutPanel;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.HasClickHandlers;

public class DesktopPhotoListUI extends Composite implements PhotoListDisplay{

	private static DesktopPhotoListUIUiBinder uiBinder = GWT
			.create(DesktopPhotoListUIUiBinder.class);
	@UiField Grid photoGrid;
	@UiField Button btnUpload;


	interface DesktopPhotoListUIUiBinder extends
			UiBinder<Widget, DesktopPhotoListUI> {
	}

	public DesktopPhotoListUI() {
		initWidget(uiBinder.createAndBindUi(this));
	    // Add images to the grid
//	    int numRows = grid.getRowCount();
//	    int numColumns = grid.getColumnCount();
//	    for (int row = 0; row < numRows; row++) {
//	      for (int col = 0; col < numColumns; col++) {
//	        grid.setWidget(row, col, new Image(Showcase.images.gwtLogo()));
//	      }
//	    }
//		photoGrid.resize(2, 2);
//		photoGrid.setWidget(1, 1, new Label("hi"));
	}

	@Override
	public void setData(List<PhotoEntity> data) {
		if(data == null || data.size() < 1)	return;
		int nSize = data.size();
		
// "photoGrid.resize(2, 2);
		if(nSize < 1)
			photoGrid.resize(1, 1);
		else
			photoGrid.resize(nSize, 1);
		
		for(int k=0; k<nSize;k++){
			PhotoEntity photo = data.get(k);
			photoGrid.setWidget(k, 0, new Image(photo.getServingUrl()));
		}
	}

	public Widget asWidget(){
		return this;
	}


	@Override
	public HasClickHandlers getLinkButton() {
		// TODO Auto-generated method stub
		return this.btnUpload;
	}
}
